package net.lab1024.sa.admin.module.business.roland.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.lab1024.sa.admin.module.business.roland.domain.form.*;
import net.lab1024.sa.admin.module.business.roland.domain.vo.RolandOrderDetailVO;
import net.lab1024.sa.admin.module.business.roland.domain.vo.RolandOrderVO;
import net.lab1024.sa.admin.module.business.roland.domain.vo.RolandRegisterVO;
import net.lab1024.sa.admin.module.business.roland.service.RolandCustomerService;
import net.lab1024.sa.admin.module.business.roland.service.RolandOrderService;
import net.lab1024.sa.common.common.domain.PageResult;
import net.lab1024.sa.common.common.domain.ResponseDTO;
import net.lab1024.sa.common.common.domain.ValidateList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;

/**
 * 客户订单表 Controller
 *
 * @Author dragon
 * @Date 2023-12-11 13:27:12
 * @Copyright dragon
 */

@RestController
@Api(tags = "")
public class RolandOrderController {

    @Autowired
    private RolandOrderService rolandOrderService;
    @Autowired
    private RolandCustomerService rolandCustomerService;

    @ApiOperation("分页查询 @author dragon")
    @PostMapping("/rolandOrder/queryPage")
    public ResponseDTO<PageResult<RolandOrderVO>> queryPage(@RequestBody @Valid RolandOrderQueryForm queryForm) {
        return ResponseDTO.ok(rolandOrderService.queryPage(queryForm));
    }

    @ApiOperation("代客下单")
    @PostMapping("/rolandOrder/add")
    public ResponseDTO<BigDecimal> add(@RequestBody @Valid RolandOrderAddForm addForm) {
        ResponseDTO<RolandRegisterVO> register = rolandCustomerService.register(addForm);
        if (!register.getOk()) {
            return ResponseDTO.error(register);
        }

        RolandOrderForm orderForm = new RolandOrderForm();
        orderForm.setCustomerId(register.getData().getCustomerId());
        orderForm.setPhone(addForm.getPhone());
        orderForm.setSeatIds(addForm.getSeatIds());
        return rolandOrderService.order(orderForm);
    }

    @ApiOperation("更新状态 @author dragon")
    @PostMapping("/rolandOrder/update")
    public ResponseDTO<String> update(@RequestBody @Valid RolandOrderUpdateForm updateForm) {
        return rolandOrderService.updateStatus(updateForm);
    }

    @ApiOperation("批量删除 @author dragon")
    @PostMapping("/rolandOrder/batchDelete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Integer> idList) {
        return rolandOrderService.batchDelete(idList);
    }

    @ApiOperation("单个删除 @author dragon")
    @GetMapping("/rolandOrder/delete/{id}")
    public ResponseDTO<String> batchDelete(@PathVariable Integer id) {
        return rolandOrderService.delete(id);
    }

    @ApiOperation("订单详情 @author dragon")
    @GetMapping("/rolandOrder/detail/{id}")
    public ResponseDTO<List<RolandOrderDetailVO>> detail(@PathVariable Integer id) {
        return rolandOrderService.detail(id);
    }


    @ApiOperation("导出")
    @GetMapping("/rolandOrder/export")
    public void export(@Valid RolandOrderQueryForm queryForm, HttpServletResponse response) {
        rolandOrderService.export(queryForm, response);
    }

}
